#pragma once
#include <string>

enum Result
{
    DivZero=1, //除零
    ModZero, //模零
    Unknown //未知
};

class Task
{
public:
    Task() //默认构造
    {}
    ~Task()
    {}
    
    Task(int d1, char op, int d2)
    :_num1(d1), _op(op), _num2(d2)
    {}

    void Run()
    {
        switch (_op)
        {
        case '+':
            _result = _num1 + _num2;
            break;
        case '-':
            _result = _num1 - _num2;
            break;
        case '*':
            _result = _num1 * _num2;
            break;
        case '/':
            {
                if(_num2 == 0) _exitcode = DivZero;
                else _result = _num1 / _num2;
            }
            break;
        case '%':
           {
                if(_num2 == 0) _exitcode = ModZero;
                else _result = _num1 % _num2;
            }            break;
        default:
            _exitcode = Unknown;
            break;
        }
    }

    void operator()() //仿函数调用
    {
        Run();
    }

   std::string GetResult()
    {
        std::string r = std::to_string(_num1);
        r += _op;
        r += std::to_string(_num2);
        r += "=";
        r += std::to_string(_result);
        r += "[code: ";
        r += std::to_string(_exitcode);
        r += "]";

        return r;
    }
    std::string GetTask()
    {
        std::string r = std::to_string(_num1);
        r += _op;
        r += std::to_string(_num2);
        r += "= ?";
        return r;
    }
private:
    int _num1;
    int _num2;
    char _op;
    int _result; //结果 
    int _exitcode; //结果是否正确
};